<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>充值</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

</head>

<body class="gray-bg" >
    <div class="wrapper wrapper-content  animated fadeInRight" id="ccbb">
        <div class="row">
            <div class="col-sm-12">
                <div class="toolbar">
                    <div id="toolbar">
<shiro:hasPermission name="recharge90:add">
                        <button onclick="toInsert();" class="btn btn-primary"><i class="fa fa-file-excel-o"></i>&nbsp;新增</button>
</shiro:hasPermission>
                    <%--<shiro:hasPermission name="recharge90:add">--%>
                            <%--<button id="btn_add" class="btn btn-primary"><i class="fa fa-plus-circle"></i>&nbsp;新增</button>--%>
                        <%--</shiro:hasPermission>--%>
                        <button id="btn_export" class="btn  btn-success"><i class="fa fa-sign-out"></i>&nbsp;导出Excel</button>
                        <%--<button id="button" class="btn btn-primary " ><i class="fa fa-check-circle"></i>&nbsp;获取选中</button>--%>
                        <%--<button id="btn_getCheck姓名" class="btn btn-primary " ><i class="fa fa-check-square"></i>&nbsp;获取选中ChekBox</button>--%>
                    </div>
                </div>
                <span id="spancc" class="spancc"></span>
                <div class="row">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>搜索条件</h5>
                            <div class="ibox-tools">
                                <a class="collapse-link">
                                    <i class="fa fa-chevron-up"></i>
                                </a>
                            </div>
                        </div>
                        <div class="ibox-content" >
                            <div class="row">
                                <div class="col-md-2">
                                            <input type="hidden" id="agent_hide">
                                            <input type="hidden" id="brand_hide">
                                            <select class="form-control" name="recharge90.agent" id="agent" onchange="javascript:selectChange(2);">
                                                <option value="">全部代理商</option>
                                            </select>
                                </div>
                                <div class="col-md-2">
                                            <select class="form-control" name="recharge90.brand" id="brand" onchange="javascript:selectChange(3);">
                                                <option value="">全部商户</option>
                                            </select>
                                </div>
                                <div class="col-md-1"><button id="btn_search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</button></div>
                            </div>
                        </div>
                    </div>
                </div>
                <table id="exampleTablePagination1"></table>
            </div>
        </div>
    </div>

    <script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/bootstrap-table.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/locale/bootstrap-table-zh-CN.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/export/bootstrap-table-export.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/editable/bootstrap-table-editable.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/layer/laydate/laydate.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
    <script type="text/javascript">
            //初始化表格对象
            var $table = $('#exampleTablePagination1');
            /*
                获取选中行的相关数据
            */
            $(function () {
                $table.on('click-row.bs.table', function (e, row, $element) {
                    $('.success').removeClass('success');
                    $($element).addClass('success');
                });
                $('#button').click(function () {
                    alert('Selected name: ' + getSelectedRow().userName);
                });

                if ('${user.identity}'=='1')//管理员登录
                {
                    var url = "${ctx}/shop/ajaxAgent.ac?guid="+new Date().getTime();
                    $.get(url,function(data){
                        data=eval(data);
                        if (data.length>0)
                        {
                            $("#agent").html("");
                            $("#agent").append('<option value="">全部代理商</option>');
                            for (var i=0;i<data.length;i++)
                            {
                                var html = "";
                                if ('${pd.agent_select}'==data[i].agent_code)
                                {
                                    html = '<option selected="selected" value="'+data[i].agent_code+'">'+data[i].agent_name+'</option>';
                                }else
                                {
                                    html = '<option value="'+data[i].agent_code+'">'+data[i].agent_name+'</option>';
                                }
                                $('#agent').append(html);
                            }
                            //选择了某个品牌
                            if ('${pd.brand_select}'!=null && '${pd.brand_select}'!='')
                            {
                                $("#brand").html("");
                                $("#brand").select2("val","");
                                $('#brand').append('<option value="">全部商户</option>');
                                var url = "${ctx}/shop/ajaxBrand.ac?agent_code=${pd.agent_select}&guid="+new Date().getTime();
                                $.get(url,function(data){
                                    data=eval(data);
                                    if (data.length>0)
                                    {
                                        for (var i=0;i<data.length;i++)
                                        {
                                            var html = null;
                                            if ('${pd.brand_select}'==data[i].brand_code)
                                            {
                                                html = '<option selected="selected" value="'+data[i].brand_code+'">'+data[i].name+'</option>';
                                            }else
                                            {
                                                html = '<option value="'+data[i].brand_code+'">'+data[i].name+'</option>';
                                            }
                                            $('#brand').append(html);
                                        }
                                    }
                                });
                            }else if ('${pd.agent_select}'!=null && '${pd.agent_select}'!=''){//选择代理商，未选择品牌
                                ajaxBrand('${pd.agent_select}');
                            }
                        }
                    });
                }else if ('${user.identity}'=='2')//代理商
                {
                    $("#agent").empty();
                    $("#agent").append('<option value="${user.identity_code}">${user.identity_name}</option>');
                    $("#agent").attr("disabled","disabled");
                    $("#brand").html("");
                    $('#brand').append('<option value="">全部商户</option>');
                    ajaxBrand('${user.identity_code}');
                    <%--var url = "shop/ajaxBrand.do?agent_code=${user.identity_code}&guid="+new Date().getTime();--%>
                    <%--$.get(url,function(data){--%>
                        <%--if (data.length>0)--%>
                        <%--{--%>
                            <%--for (var i=0;i<data.length;i++)--%>
                            <%--{--%>
                                <%--var html = null;--%>
                                <%--if ('${pd.brand_select}'==data[i].brand_code)--%>
                                <%--{--%>
                                    <%--html = '<option selected="selected" value="'+data[i].brand_code+'">'+data[i].name+'</option>';--%>
                                <%--}else--%>
                                <%--{--%>
                                    <%--html = '<option value="'+data[i].brand_code+'">'+data[i].name+'</option>';--%>
                                <%--}--%>
                                <%--$('#brand').append(html);--%>
                            <%--}--%>
                        <%--}--%>
                    <%--});--%>
                }else if ('${user.identity}'=='3')//品牌商户
                {
                    //固定代理商
                    $("#agent").empty();
                    $("#agent").append('<option value="${agent.agent_code}">${agent.agent_name}</option>');
                    $("#agent").attr("disabled","disabled");
                    //固定品牌商户
                    $("#brand").html("");
                    $("#brand").append('<option value="${user.identity_code}">${user.identity_name}</option>');
                    $("#brand").attr("disabled","disabled");
                }
            });
            function getSelectedRow() {
                var index = $table.find('tr.success').data('index');
                return $table.bootstrapTable('getData')[index];
            }


                    /*
                        每一列详情格式化数据
                     */
            function formDetail(index, row) {
                return row.detail+index;
            }

            //动态加载代理商
            function ajaxAgent()
            {
                var url = "${ctx}/shop/ajaxAgent.ac?guid="+new Date().getTime();
                $.get(url,function(data){
                    data=eval(data);
                    if (data.length>0)
                    {
                        alert(data);
                        for (var i=0;i<data.length;i++)
                        {
                            var html = '<option value="'+data[i].agent_code+'">'+data[i].agent_name+'</option>';
                            $('#agent').append(html);
                        }
                    }
                });
            }

            //动态加载品牌
            function ajaxBrand(agent_code)
            {
                $("#brand").html("");
                $('#brand').append('<option value="">全部商户</option>');
                var url = "${ctx}/shop/ajaxBrand.ac?agent_code="+agent_code+"&guid="+new Date().getTime();
                $.get(url,function(data){
                    data=eval(data);
                    if (data.length>0)
                    {
                        for (var i=0;i<data.length;i++)
                        {
                            var html = '<option value="'+data[i].brand_code+'">'+data[i].name+'</option>';
                            $('#brand').append(html);
                        }
                    }
                });
            }

            function selectChange(type)
            {
                if (type==2)//改代理商
                {
                    var user_code = $('#agent option:selected').val();
                    ajaxBrand(user_code);
                }else if(type == 3){
                    var brand_code = $('#brand option:selected').val();
                }
            }

            function showPopup(){
                    //自定页
                    parent.layer.open({
                        type: 2,
                        shift:4,//动画类型
                        moveType:1,
                        maxmin: true,
                        shadeClose: true, //开启遮罩关闭
                        area: ['800px', '600px'],
                        content: '${ctx}/jsp/basic/recharge90_edit.jsp',
                        success: function(layero, index){
                            var body = parent.layer.getChildFrame('body', index);
                            //var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                           // console.log(body.html()); //得到iframe页的body内容
                        },
                        cancel: function(index){
                            return true;
                        }
                    });
            }

            ////////////////////////////////////////////////////////////////////////////////////////以下是通过js方式初始化BootStrapTable/////////////////////////////////////////////

            $table.bootstrapTable({
                url: "${ctx}/recharge90/showDoQuery.ac",
                method: 'post',
                contentType: "application/x-www-form-urlencoded",//必须的
                dataType: "json",
                pageList:[10, 20, 50, 100],//会根据当前的数据量加载合适的pageList
                height: ($(window).height()-200) ,
                //cardView:true,//是否自适应手机
                pagination: true, //分页
                // queryParamsType: "limit",
                singleSelect: false,
                cache:false,
                sortName:"createTime",
                search: false, //显示搜索框
                toolbar:"#toolbar",
                queryParams: queryParams,//参数
                searchOnEnterKey:true,
                showColumns:false,
                showRefresh:false,
                showToggle:false,
                showPaginationSwitch:false,
                smartDisplay:true,
                detailView:false,
                detailFormatter:function(index, row, element){
                    return row.detail;
                },
                sidePagination: "server", //服务端处理分页
                columns: [
                {
                    visible:false,
                    field:'code'
                },
                {
                    title: '代理商',
                    field: 'agent_name',
                    titleTooltip: '点击可以进行排序操作',
                    align: 'center'
                },
                {
                    title: '品牌',
                    field: 'brand_name',
                    align: 'center'
                },
                {
                    title: '久零券总额',
                    field: 'total_90',
                    align: 'center',
                    formatter:function(value,row,index){
                        return value/100;
                    }
                },
                {
                    title: '消费的人民币',
                    field: 'total_rmb',
                    align: 'center',
                    formatter:function(value,row,index){
                        return value/100;
                    }
                },
                {
                    title: '久零余额',
                    field: 'balance_90',
                    align: 'center',
                    formatter:function(value,row,index){
                        return value/100;
                    }
                },
                {
                    title: '充值后余额',
                    field: 'totalNow_90',
                    align: 'center',
                    formatter:function(value,row,index){
                        return value/100;
                    }
                },
                {
                    title: '操作人',
                    field: 'person_name',
                    align: 'center'
                },
                {
                    title: '操作时间',
                    field: 'create_time',
                    align: 'center'
                },
                {
                    title: '备注',
                    field: 'notes',
                    align: 'center'
                }
            ]
            });

            /*
                搜索按钮
            */
            $("#btn_search").click(function(){
                $table.bootstrapTable('selectPage', 1);
                $table.bootstrapTable('refresh', queryParams);
            });

            /*
                传递的参数
            */
            function queryParams(params) {
                var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,  //页面大小
                    offset: params.offset, //页码
                    pageindex:params.pageNumber,
                    agent: $("#agent").val(),
                    brand: $("#brand").val()
                };
                $("#agent_hide").val($("#agent").val());
                $("#brand_hide").val($("#brand").val());
                return temp;
            }
            ///////////////////////////////////////////////////////////////toolbar///////////////////////////////////////
            //新增
            $("#btn_add").click(function(){
                showPopup();
            });

            //批量导出
            $("#btn_export").click(function(){
                var agent = $("#agent_hide").val();
                var brand = $("#brand").val();
                window.location.href="${pageContext.request.contextPath}/recharge90/doExcel.ac?agent="+agent+"&brand="+brand;
            });


            //获取选中的CheckBox
            $("#btn_getCheck").click(function(){
               alert('getSelections: ' + JSON.stringify($table.bootstrapTable('getSelections')));
               alert("客户信息:"+$table.bootstrapTable('getSelections')[0].userName);
            });

            /*
            获取所有选中的CheckBox的主键值 【数组】
             */
            function getSelections() {
                return $.map($table.bootstrapTable('getSelections'), function (row) {
                    return row.id;
                });
            }

            /*
                BootStrapTable CheckBox 状态初始化
             */
            function stateFormatter(value, row, index) {
                if (row.id === 2) {
                    return {
                        disabled: true,
                        checked: true
                    };
                }
                if (row.id === 0) {
                    return {
                        disabled: true,
                        checked: true
                    }
                }
                return value;
            }

            //新增
            function toInsert()
            {
                showPopup();
            }



        </script>
</body>


</html>
